﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace HelloWorld.Startup.MVVM
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Controls;

    //LocalizationLibrary References
    using LocalizationLibrary;

    /// <summary>
    /// Defines a base class for view.
    /// </summary>
    public class View : UserControl
    {
        //Dependency Properties

#if SILVERLIGHT
        /// <summary>
        /// Identifies the ViewModelProperty dependency property.
        /// </summary>
        public static readonly DependencyProperty ViewModelProperty =
            DependencyProperty.Register("ViewModel", typeof(IViewModel), typeof(View), new PropertyMetadata(null));

        /// <summary>
        /// Identifies the LocalizationModelProperty dependency property.
        /// </summary>
        public static readonly DependencyProperty LocalizationModelProperty =
            DependencyProperty.Register("LocalizationModel", typeof(ILocalizationModel), typeof(View), new PropertyMetadata(null));
#else
        /// <summary>
        /// Identifies the ViewModelProperty dependency property.
        /// </summary>
        public static readonly DependencyProperty ViewModelProperty =
            DependencyProperty.Register("ViewModel", typeof(IViewModel), typeof(View), new UIPropertyMetadata(null));

        /// <summary>
        /// Identifies the LocalizationModelProperty dependency property.
        /// </summary>
        public static readonly DependencyProperty LocalizationModelProperty =
            DependencyProperty.Register("LocalizationModel", typeof(ILocalizationModel), typeof(View), new UIPropertyMetadata(null));
#endif
        //Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        public View()
        {
            this.Loaded += (_sender, _e) =>
            {
                Binding binding = new Binding("ViewModel");
                binding.Source = this;
                binding.Mode = BindingMode.OneWay;
                this.SetBinding(View.DataContextProperty, binding);
            };
        }

        //Properties

        /// <summary>
        /// Gets the presention models.
        /// </summary>
        public virtual IViewModel ViewModel
        {
            get { return (IViewModel)GetValue(ViewModelProperty); }
            set { SetValue(ViewModelProperty, value); }
        }

        /// <summary>
        /// Gets the localization models.
        /// </summary>
        public virtual ILocalizationModel LocalizationModel
        {
            get { return (ILocalizationModel)GetValue(LocalizationModelProperty); }
            set { SetValue(LocalizationModelProperty, value); }
        }

    }
}
